package sg.edu.nus.iss.phoenix.schedule.entity;

import java.io.Serializable;
import java.util.ArrayList;

import sg.edu.nus.iss.phoenix.schedule.service.DateUtil;
import sg.edu.nus.iss.phoenix.user.entity.Presenter;
import sg.edu.nus.iss.phoenix.user.entity.Producer;

/**
 * 
 */
public class Schedule implements Cloneable, Serializable{
	
	private static final long serialVersionUID = -5285675634913860175L;
	/**
	 * 
	 */
	private ArrayList<ProgramSlot> programSlotList;
	private String dateOfSchedule;

	/**
	 * Get- and Set-methods for persistent variables. The default behaviour does
	 * not make any checks against malformed data, so these might require some
	 * manual additions.
	 */
	public String getDateOfSchedule() {
		return dateOfSchedule;
	}

	public void setDateOfSchedule(String dateOfSchedule) throws Exception  {
		this.dateOfSchedule = dateOfSchedule;
		
	}

	public ArrayList<ProgramSlot> getProgramSlotList() {
		return programSlotList;
	}

	public void setProgramSlotList(ArrayList<ProgramSlot> programSlotList) {
		this.programSlotList = programSlotList;
	}
	
	/**
	 * getProgramSlotByTimeSlot will return a program slot 
	 * which is based on a particular time
	 * 
	 * @param time
	 * 			Time needs to be used for getting program slot
	 * 
	 * @return ProgramSlot
	 * 			This method will return a program slot
	 */
	public ProgramSlot getProgramSlotByTimeSlot(String time) throws Exception{
		ProgramSlot value = new ProgramSlot();
		value.setProgramSlotId(0);
		value.setPresenter(new Presenter());
		value.setProducer(new Producer());
		
		value.setProgramName("Play Music");
		for (ProgramSlot ps : programSlotList) {
			String timeFormat = DateUtil.convertToMySQLTimeFormat(ps.getStartTime());
			if(timeFormat.startsWith(time.substring(0, 5)))
				value = ps;
		}
		return value;
	}	
}
